<template>
  <a-card :bordered="false">
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      class="j-table-force-nowrap"
      :scroll="{x:true}"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      @change="handleTableChange"
    >
      <span slot="switch" slot-scope="text, record">
        <a-switch
          @change="changeStatus(record)"
          :checked="getSataus(record['templateStatus'])"
          checked-children="上线"
          un-checked-children="下线"
          default-checked
        />
      </span>
      <span slot="actionName">
        <a-button size="small" @click="openCreatModel()" type="primary" icon="plus">新增</a-button>
      </span>
      <span slot="action" slot-scope="text, record">
        <a @click="handleTempCheck(record, '')">查看</a>
        <template v-if="record.templateStatus == '0'">
          <a-divider type="vertical" />
          <a @click="handleEdit(record, '')">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </template>
      </span>
    </a-table>
    <!-- table区域-end -->
    <createTemp ref="creatModel" @ok="modalFormOk"></createTemp>
    <projectListModal ref="modalForm" @ok="modalFormOk"></projectListModal>
    <tempCheck ref="tempCheck"></tempCheck>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { httpAction, getAction, postAction, deleteAction } from '@/api/manage'
import columns from './indexColumns'
import createTemp from './createTemp'
import projectListModal from './projectListModal'
import tempCheck from './tempCheck'

export default {
  name: 'bmmb',
  mixins: [JeecgListMixin],
  components: {
    createTemp,
    projectListModal,
    tempCheck,
  },
  data() {
    return {
      // 表头
      columns: columns(this),
      url: {
        list: '/performcheck/checkTemplateInfo/queryTemplateList',
        delete: '/performcheck/checkTemplateInfo/deleteTemplate',
        status: '/performcheck/checkTemplateInfo/switchTemplateStatus',
      },
      dataSource: [],
    }
  },
  computed: {},
  methods: {
    handleTempCheck(record) {
      this.$refs.tempCheck.check(record)
    },
    getSataus(status) {
      if (status == 0) {
        return false
      } else {
        return true
      }
    },
    changeStatus(record) {
      httpAction(
        this.url.status,
        {
          id: record.id,
          templateStatus: record.templateStatus == '0' ? '1' : '0',
        },
        'put'
      ).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.error(res.message)
        }
      })
    },
    openCreatModel() {
      this.$refs.creatModel.add()
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
@import '~@assets/less/TableExpand.less';
</style>